/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.practica.dao;

import edu.practica.model.Bus;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import java.util.List;

/**
 *
 * @author Algo
 */
@Stateless
public class BusDAO {
 
    @PersistenceContext
    private EntityManager entityManager;

    public BusDAO() {
    }
    
   
    
    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public void registrar(Bus bus) {
        entityManager.persist(bus);
    }
    
    public void modificar(Bus bus) {
        System.out.println("BusDAO.modificar:" + bus);
        entityManager.merge(bus);
    }
    
     public List<Bus> listBus() {
        List<Bus> list = null;
        
        TypedQuery<Bus> query = 
                entityManager.createQuery("SELECT p FROM Bus p", Bus.class);
        list = query.getResultList();
        
        return list;
    }
    
}
